/**
 * 
 */
package edu.rice.test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D.Double;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * @author frogy
 * 
 */
public class PaintIMs extends JPanel {
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		for (int i = 0; i < numCircle; i++) {
			g2.draw(new Ellipse2D.Double(xini[i], 100, cirSize, cirSize));
			g2.draw(new Ellipse2D.Double(x[i], 500, cirSize, cirSize));
		}
		// Image img = createImage();
		// g.drawImage(img, 20, 20, this);
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new PaintIMs());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(1000, 1000);
		frame.setVisible(true);
	}

	private Image createImage() {
		BufferedImage bufferedImage = new BufferedImage(1010, 600,
				BufferedImage.TYPE_3BYTE_BGR);
		Graphics2D g2 = bufferedImage.createGraphics();
		g2.setColor(Color.WHITE);
		g2.fill(new Rectangle2D.Double(0,0,1010,600));
		g2.setColor(Color.red);
		for (int i = 0; i < numCircle; i++) {
			g2.draw(new Ellipse2D.Double(xini[i], 100, cirSize, cirSize));
			g2.draw(new Ellipse2D.Double(x[i], 500, cirSize, cirSize));
		}
		return bufferedImage;
	}

	public void saveImage(String filename) {
		try {
			File imOut = new File(filename);
			ImageIO.write((BufferedImage) createImage(), "png", imOut);
		} catch (IOException e) {
		}
	}

	private int numCircle;

	private double cirSize;

	private double[] x;

	private double[] xini;

	public void getParam(int num, double size, double[] x, double[] xini) {
		numCircle = num;
		cirSize = size * 10;
		this.x = x;
		this.xini = xini;
		for (int i = 0; i < this.x.length; i++) {
			this.x[i] *= 10;
			this.xini[i] *= 10;
		}
	}
}
